﻿namespace _41_C_中unsafe和不安全代码
{
    internal class Program
    {
        static unsafe void Main(string[] args)
        {
            Console.Title = "C#中unsafe和不安全代码";

            //TestStruct tesStruct = new TestStruct();

            //Console.WriteLine((uint)&tesStruct);
            //Console.WriteLine(sizeof(TestStruct));

            //int a = 100;
            //int* b = &a;
            //Console.WriteLine($"b的值：{b->ToString()}");//b-> 是 C# 中用于访问指针类型的成员的语法
            //Console.WriteLine($"b的地址：{(uint)b}");

            //int* c=stackalloc int[4];
            //*c = 200;
            //Console.WriteLine(*c);

            int a = 10;
            int b = 20;

            int* c = &a;
            int* d = &b;

            Console.WriteLine($"交换前{a} {b}");
            Swap(c, d);
            Console.WriteLine($"交换后{a} {b}");

            Console.ReadKey();
        }

        public unsafe static void Swap(int* x, int* y)
        {
            int temp = *x;
            *x = *y;
            *y = temp;
        }
    }
}
